use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct ServerConfig {
    pub host: String,
    pub port: u16,
}

#[derive(Debug, Deserialize)]
pub struct HuaweiCloudConfig {
    pub base_url: String,
    pub access_token: String,
    pub project_id: String,
}

#[derive(Debug, Deserialize)]
pub struct Settings {
    pub server: ServerConfig,
    pub huawei_cloud: HuaweiCloudConfig,
    pub log_level: String,
}

impl Settings {
    pub fn new() -> Result<Self, config::ConfigError> {
        Config::builder()
            .add_source(File::with_name("config/default"))
            .add_source(Environment::with_prefix("OPCUA"))
            .build()?
            .try_deserialize()
    }
}